#pragma once
#include <game/Config.h>
#include <game/ScreenBackendFactory.h>

#include <boost/shared_ptr.hpp>

#include <xml/Object.h>
#include <memory>
#include <vector>

namespace liba {
namespace lib3d {
namespace node {
class Node;
class Camera;
} // namespace node
} // namespace lib3d
} // namespace liba

ARELLO_GAME_NAMESPACE_DECL_START

class Properties;

namespace controls {
class Control; 
class ControlFactory;
} // namespace controls

class Root;
class Screen;
class ScreenBackend;

class ScreenDefinition
	: private xml::ObjectANSI
{
private:
	virtual bool on_node(xml::Provider * prov, const std::string & name);
	virtual bool on_attribute(xml::Provider * prov, const std::string & name, const std::string & value);
	virtual bool on_end_node(xml::Provider * prov);
public:
	ScreenDefinition();
	~ScreenDefinition();

	xml::ObjectANSI* GetLoader() { return this; }
	void SetBackendFactory(const ScreenBackendFactory& value) { this->backendFactory = value; }
	void SetControlFactory(const controls::ControlFactory* value) { this->controlFactory = value; }

	// Call this method only once since it passes ownership of rootNode to the newly created screen.
	std::auto_ptr<Screen> CreateScreen(Root& root);
private:
	std::auto_ptr<liba::lib3d::node::Node> rootNode;
	std::auto_ptr<liba::lib3d::node::Camera> mainCamera;
	std::auto_ptr<Properties> properties;
	std::auto_ptr<ScreenBackend> backend;
	std::vector<boost::shared_ptr<controls::Control> > controls;
	ScreenBackendFactory backendFactory;
	const controls::ControlFactory* controlFactory;
	std::string backendClass;
};

ARELLO_GAME_NAMESPACE_DECL_END